#ifndef DUMPFILE_H
#define DUMPFILE_H

typedef unsigned      char Iu8 ;
typedef   signed      char Is8 ;
typedef unsigned     short Iu16;
typedef   signed     short Is16;
typedef unsigned      long Iu32;
typedef   signed      long Is32;
typedef unsigned long long Iu64;
typedef   signed long long Is64;
typedef unsigned      int  Ibool;
typedef struct {
    union {
	Iu8  AsID [8];
	Iu32 AsData [2];
    } ID;
} WWName;

#define NET_USHORT(u16)   ((Iu16)((((Iu16)(u16)) >> 8) | (((Iu16)(u16)) << 8)))
#define NET_ULONG(u32)   ((Iu32)(NET_USHORT((u32) >> 16) | (NET_USHORT(u32 & 0xFFFF) << 16)))
#define NET_SHORT(i16)   ((Is16)NET_USHORT(i16))
#define NET_LONG(i32)   ((Is32)(NET_USHORT((i32) >> 16) | (NET_USHORT(i32 & 0xFFFF) << 16)))

static Iu32 endianness = 0xdeadbeef; 
enum endianness { BIG = 1, LITTLE, UNKNOWN };

#define ENDIANNESS ( *(const unsigned char *)&endianness == 0xef ? LITTLE \
                   : *(const unsigned char *)&endianness == 0xde ? BIG \
                   : UNKNOWN)
#ifdef __cplusplus
extern "C" {
#endif
int Dmp_Load(char *path);
Iu32 Dmp_Size();
void * Dmp_OffsetToBuffer(Iu32 offset);
Iu32 Dmp_Iu32AtOffset(Iu32 offset, Iu32 endian);
Iu16 Dmp_Iu16AtOffset(Iu32 offset, Iu32 endian);
Iu8 Dmp_Iu8AtOffset(Iu32 offset);
Iu32 Dmp_Iu32AtPpc(Iu32 ppc);
Iu16 Dmp_Iu16AtPpc(Iu32 ppc);
Iu8 Dmp_Iu8AtPpc(Iu32 ppc);
Iu32 Dmp_SGE_Address(Iu32 index);
Iu32 Dmp_SGE_Length(Iu32 index);
Iu32 Dmp_SG_Length();
void Dmp_PrintHeader();
Iu32 Dmp_OffsetToPpc(Iu32 offset);
Iu32 Dmp_PpcToOffset(Iu32 ppc);
Is32 Dmp_Iu32Search(Iu32 entry, Iu32 start);
#ifdef __cplusplus
}
#endif
#endif
